var rootPath = getRootPath();	

var loveModelNum = 0;


//加载心仪车型
function initLoveMode(){
	$.ajax({
        type:"GET", 
        url:rootPath+"/wechat/api/loveModel", 
        dataType:"json",      
        async: false,
        contentType:"application/json",               
        data:null, 
        success:function(data){ 
        	
        	if(data==undefined || data=='' || data.length==0){
        		$("#noLoveModelDiv").show();
        		$("#existLoveModeDiv").hide();
        	}else{
        		$("#noLoveModelDiv").hide();
        		$("#existLoveModeDiv").show();
                // 编辑轮播信息数据
    			var wholeHtml = '';
    			// 轮播（Carousel）指标
    			var carousel_indicatorsHtml = '<ol class="carousel-indicators">';
    			
    			// 轮播（Carousel）项目
    			var carousel_innerHtml = '<div class="carousel-inner">';
    			
    			var indexTemp= 0;
    			$.each(data,function(carModelIndex,carModelObj){
    				indexTemp = carModelIndex;
    				if (0 == carModelIndex){
    					
//    				    carousel_indicatorsHtml+= '<li data-target="#myCarInfos" data-slide-to='+carModelIndex+' class="active"></li>';
    					carousel_indicatorsHtml += '<li class="active"><a href="#" class="active" packageCode='+carModelObj.packageCode+' onclick=setPackageCode(this)><img alt="" src="'+rootPath+'/images/'+carModelObj.brandName+'/外观/'+carModelObj.seriesName+'/'+carModelObj.seriesName+'.jpg'+'"  data-target="#myCarInfos" data-slide-to="'+ carModelIndex +'" class="img-responsive"/ ></a></li>';
    				    carousel_innerHtml += "<div class='item active'>";
    				    //品牌CODE赋值
    				    $("#defaultPackageCode").val(carModelObj.packageCode);
    				} else {
//    					carousel_indicatorsHtml+= '<li data-target="#myCarInfos" data-slide-to='+carModelIndex+' ></li>';
    					carousel_indicatorsHtml += '<li><a href="#" packageCode='+carModelObj.packageCode+' onclick=setPackageCode(this)><img alt="" src="'+rootPath+'/images/'+carModelObj.brandName+'/外观/'+carModelObj.seriesName+'/'+carModelObj.seriesName+'.jpg'+'"  data-target="#myCarInfos" data-slide-to="'+carModelIndex+'" class="img-responsive"/ ></a></li>';
    					carousel_innerHtml += "<div class='item'>";
    				}
    				var localPrice = carModelObj.localPrice;
    				var guidePrice = carModelObj.guidePrice;
    				if(localPrice==undefined || localPrice==''){
    					localPrice = '';
    				}else{
    					localPrice = localPrice.toFixed(2);
    				}
    				if(guidePrice==undefined || guidePrice==''){
    					guidePrice = '';
    				}else{
    					guidePrice = guidePrice.toFixed(2);
    				}
    				
    				carousel_innerHtml += '<table style="width: 99%">';
    				carousel_innerHtml += '  <tr>';
    				carousel_innerHtml += "      <td width='25%' align='center' valign='middle'>";
//    				carousel_innerHtml += "          <div class=''>";
    				carousel_innerHtml += "           <h6  style='font: bolder;color: #000'>"+carModelObj.packageName+"</h6>";
//    				carousel_innerHtml += "           <h6><span class='text-muted'>"+carModelObj.seriesName+"</span></h6>";
//    				carousel_innerHtml += "          </div>";
    				carousel_innerHtml += "       </td>";
    				carousel_innerHtml += '      <td width="35%" align="center"><img src="'+rootPath+'/images/'+carModelObj.brandName+'/外观/'+carModelObj.seriesName+'/'+carModelObj.seriesName+'.jpg'+'" width="150" height="70"></td>';
    				carousel_innerHtml += '      <td width="45%">';
    				if(carModelObj.packageColors!=undefined && carModelObj.packageColors!='' && carModelObj.packageColors.length >0){
        				carousel_innerHtml += '          <div>';
        				carousel_innerHtml += '             <table>';
        				carousel_innerHtml += '                <tr>';
        				carousel_innerHtml += '                  <td><a type="pre" len='+carModelObj.packageColors.length+' packageCode='+carModelObj.packageCode+'  onclick="dySelectColor(this)" href="#">＜&nbsp;&nbsp;</a></td>';
        				carousel_innerHtml += '                        <input id="'+carModelObj.packageCode+'_currentIndex" type="hidden" value="0">';
            			$.each(carModelObj.packageColors,function(packageColorIndex,packageColorObj){
            				carousel_innerHtml += '                        <input id="'+carModelObj.packageCode+'_'+packageColorIndex+'_colorId" type="hidden" value="'+packageColorObj.colorId+'">';
            				if(packageColorIndex==0){
            					if(carModelIndex==0){
            						$("#defaultColorId").val(packageColorObj.colorId);
            					}

                				carousel_innerHtml += '                  <td class="colorParam" id="'+carModelObj.packageCode+'_'+packageColorIndex+'_name"><h6>'+packageColorObj.colorName+'&nbsp;</h6></td>';
                				carousel_innerHtml += '                  <td id="'+carModelObj.packageCode+'_'+packageColorIndex+'_color"><div  style="background-color: #'+packageColorObj.colorValue+';width: 20px;height: 10px"></div></td>';
            				}else{
                				carousel_innerHtml += '                  <td class="colorParam" id="'+carModelObj.packageCode+'_'+packageColorIndex+'_name" style="display: none"><h6>'+packageColorObj.colorName+'&nbsp;</h6></td>';
                				carousel_innerHtml += '                  <td id="'+carModelObj.packageCode+'_'+packageColorIndex+'_color" style="display: none"><div  style="background-color: #'+packageColorObj.colorValue+';width: 20px;height: 10px"></div></td>';
            				}
            			});
        				
        				carousel_innerHtml += '                  <td><a type="next" len='+carModelObj.packageColors.length+' packageCode='+carModelObj.packageCode+'  onclick="dySelectColor(this)" href="#">&nbsp;&nbsp;＞</a></td>';
        				carousel_innerHtml += '                </tr>';
        				carousel_innerHtml += '             </table>';
        				carousel_innerHtml += '          </div>';
    				}
    				carousel_innerHtml += '          <h6><span>指导价：</span><span>'+guidePrice+'</span>万</h6> <p><h6><font color="red"><span>本店价：</span><span>'+localPrice+'</span>万<font></h6></p>';
    				carousel_innerHtml += '      </td>';
    				carousel_innerHtml += "  </tr>";
    				carousel_innerHtml += "</table>";
    				carousel_innerHtml += "<input type='hidden' id = 'packageCode_"+carModelIndex+"' value='"+carModelObj.packageCode+"' /></div>";
    			});
    			
    			loveModelNum = parseInt(indexTemp)+1;
    			
    			carousel_innerHtml += "<div class='item'>";
				carousel_innerHtml += '<table style="width: 99%">';
				carousel_innerHtml += '  <tr>';
				carousel_innerHtml += "      <td width='25%' align='left' valign='middle'>";
//				carousel_innerHtml += "          <div class=''>";
				carousel_innerHtml += "           <h6  style='font: bolder;color: #000'><a href='#' class='selectBrandSeries''><span class='packageNameSpan'>请选择心仪车型</span><span class='glyphicon glyphicon-chevron-right'></span></a></h6>";
//				carousel_innerHtml += "           <h6><span class='text-muted'>"+carModelObj.seriesName+"</span></h6>";
//				carousel_innerHtml += "          </div>";
				carousel_innerHtml += "       </td>";
				carousel_innerHtml += '      <td width="35%" align="center"><img id="seriesImageAp" src="'+rootPath+'/images/allCar.png'+'" width="150" height="70"></td>';
				carousel_innerHtml += '      <td width="45%" align="center"><div class="attachSelectModelPackageDiv"></div><h6><span>指导价：</span><span class="guidePriceAp"></span></h6> <p><h6><font color="red"><span>本店价：</span><span class="localPriceAp"></span><font></h6></p></td>';
				carousel_innerHtml += "  </tr>";
				carousel_innerHtml += "</table>";
    			
//    			carousel_innerHtml += "<table>";
//    			carousel_innerHtml += "  <tr align='center'>";
//    			carousel_innerHtml += "     <td align='right' width='40%'><a href='#'>";
//    			carousel_innerHtml += '         <img id="seriesImageAp" src="'+rootPath+'/images/allCar.png'+'" width="150" height="70"></a>';
//    			carousel_innerHtml +="      </td>";
//    			carousel_innerHtml +="      <td width='10%'></td>";
//    			carousel_innerHtml += "     <td align='left'><a href='#'>123412</a><p>";
//    			carousel_innerHtml +="         <h6  style='font: bolder;color: #000'><a href='#' class='selectBrandSeries''><span class='packageNameSpan'>请选择心仪车型</span><span class='glyphicon glyphicon-chevron-right'></span></a></h6>";
//    			carousel_innerHtml +="         <p><h6><span>指导价：</span><span class='guidePriceAp'></span></h6></p>";
//    			carousel_innerHtml +="         <p><h6><font color='red'><span>本店价：</span><span class='localPriceAp'></span></font></h6></p>";
//    			carousel_innerHtml +="         <div id='attachSelectModelPackageDiv'></div>";
//    			carousel_innerHtml +="       </td>";
//    			carousel_innerHtml +="   </tr>";
//    			carousel_innerHtml +="</table>";
//    			carousel_innerHtml +="</div>";
    			
    			
    			carousel_indicatorsHtml += "</ol> ";
    			carousel_innerHtml += "</div>";
    			
    			// 轮播（Carousel）导航
//    			var carousel_controlHtml = '<a class="carousel-control left"  href="#myCarInfos"  data-slide="prev" type = "button">&lsaquo;</a>';
//    			    carousel_controlHtml += '<a class="carousel-control right" href="#myCarInfos"  data-slide="next" type = "button">&rsaquo;</a>';
//    			
    			$("#myCarInfos").append(carousel_indicatorsHtml);
    			$("#myCarInfos").append(carousel_innerHtml);
        		
        	}
			
        	
        },
        error:function(data){
        }
     });

}

$(document).ready(function(){
	
	 var packageCode = getQueryParamValue("packageCode");
	 if(packageCode!=undefined && packageCode!=''){
		 
 		$("#noLoveModelDiv").show();
		$("#existLoveModeDiv").hide();

	 	$.ajax({
	 		method : 'get',
	 		url : rootPath+'/wechat/api/showroom/packages?packageCode='+packageCode,
	 		error:function(XMLHttpRequest, ajaxOptions, thrownError){
	 			alert("连接服务器错误!");
	 		},
	 		success : function(resultData){
	 			
				$("#seriesImageAp").attr("src",rootPath+'/images/'+resultData.brandName+'/外观/'+resultData.seriesName+'/'+resultData.seriesName+'.jpg');
				$("#seriesImageApNoLoveModel").attr("src",rootPath+'/images/'+resultData.brandName+'/外观/'+resultData.seriesName+'/'+resultData.seriesName+'.jpg');

	 	        $("#defaultBrandCode").val(resultData.brandCode);
	 	        $("#defaultSeriesCode").val(resultData.seriesCode);
	 	        $("#defaultModelCode").val(resultData.modelCode);
	 	        $("#defaultPackageCode").val(resultData.packageCode);
	 			
	 			$(".packageNameSpan").html(resultData.packageName);
	 			
	 			var guidePriceTemp = resultData.guidePrice;
	 			if(guidePriceTemp!=undefined && guidePriceTemp!=''){
		 			$(".guidePriceAp").html(guidePriceTemp+"万");
	 			}
	 			var localPriceTemp = resultData.localPrice;
	 			if(localPriceTemp!=undefined && localPriceTemp!=''){
		 			$(".localPriceAp").html(localPriceTemp+"万");
	 			}
	 			
	 			loadPackageColors(packageCode);
	 		}
	 	});
	 }else{
		initLoveMode();
	 }
	
	
	// 停止自动轮播
	$('#myCarInfos').carousel({
		interval: false
	})
	// 停止自动轮播
	$("#myCarInfos").carousel('pause');
	
/////////////////////////////////////
	
	$('#myCarInfos').hammer().on('swipeleft', function(){
		$(this).carousel('next');
	});
	
	$('#myCarInfos').hammer().on('swiperight', function(){
		$(this).carousel('prev');
	});

////////////////////////////////////
	
	
    $('#myCarInfos').on('slid.bs.carousel', function (e) {
	   	 var active = $(e.target).find('.carousel-inner > .item.active');
	   	 var ccindex = active.index();
	   	 var tempColorId = '';
	   	 
	   	 //该分支判断用户区分-是心仪车型还是这个需要新增的车型
	   	 if(ccindex == loveModelNum){
		   	 $("#defaultPackageCode").val($("#defaultPackageCode_ex").val());
		   	 var packageCode = $("#defaultPackageCode_ex").val();
             if(packageCode!=undefined && packageCode!=''){
    		   	 tempColorId = $("#"+packageCode+"_0_colorId_ex").val();
    		   	 
 				    //每次滑动时-默认选择最初的颜色
    				$("#"+packageCode+"_0_name_ex").show();
    				$("#"+packageCode+"_0_color_ex").show();
    				
    			   	var tdLength = $("#"+packageCode+"_0_name_ex").siblings('.colorParam');
    			   	if(tdLength!=undefined && tdLength!=''){
    			   		tdLength = parseInt(tdLength.length)+1;
    			   		for(var i=1;i<=tdLength;i++){
    						$("#"+packageCode+"_"+i+"_name_ex").hide();
    						$("#"+packageCode+"_"+i+"_color_ex").hide();
    			   		}
    			   	}
             }


	   	 }else{
		   	 $("#defaultPackageCode").val($("#packageCode_"+ccindex).val());
		   	 var packageCode = $("#packageCode_"+ccindex).val();
		   	 tempColorId = $("#"+packageCode+"_0_colorId").val();
		   	 
		   	 
			//每次滑动时-默认选择最初的颜色
			$("#"+packageCode+"_0_name").show();
			$("#"+packageCode+"_0_color").show();
						
		   	var tdLength = $("#"+packageCode+"_0_name").siblings('.colorParam');
		   	if(tdLength!=undefined && tdLength!=''){
		   		tdLength = parseInt(tdLength.length)+1;
		   		for(var i=1;i<=tdLength;i++){
					$("#"+packageCode+"_"+i+"_name").hide();
					$("#"+packageCode+"_"+i+"_color").hide();
		   		}
		   	}

	   	 }
	   	 if(tempColorId!=undefined && tempColorId!=''){
		 	 $("#defaultColorId").val(tempColorId);
	   	 }else{
		 	 $("#defaultColorId").val("");
	   	 }

    });
	
	
	//加载服务顾问
	$.ajax({
        type:"GET", 
        url:rootPath+"/wechat/api/potentialUsers/counselor/selectCounselor?positionId=601", 
        dataType:"json",      
        async: false,
        contentType:"application/json",               
        data:null, 
        success:function(data){ 
			var options = [];
			options.push('<option value="0">请选择您的销售顾问</option>');
			$.each(data,function(carModelIndex,advisersObj){
				options.push("<option value='"+advisersObj.userId  +"'>"+advisersObj.userName+"</option>");
			});
			
			$("#salesConsultantId_askingPrice").append(options.join(""));
        },
        error:function(data){
        	alert("数据刷新失败，请联系管理员！");
        }
     });

	 
	 //提交询价
	 $("#submitAskingPrice").click(function(){
		 
		 var defaultPackageCodeTemp=$("#defaultPackageCode").val();
		 if(defaultPackageCodeTemp==undefined || defaultPackageCodeTemp==''){
				$('#selectLoveModelTop').modal({
					keyboard: false,
					backdrop:false
				});
			return;
		 }
		 
		 
	   	 $('#askingPriceForm').bootstrapValidator('validate');
	     var isValid=$("#askingPriceForm").data("bootstrapValidator").isValid();

	     if(!isValid){
	     	return;
	     }
	     
	     
	    var data={
	    	personalName:"",
	    	phone:"",
	    	dealerCode:"",
	    	packageCode:"",
	    	salesConsultantId:"",
	    	startDate:"",
	    	askingPriceContent:"",
	    	colorId:""
	    }; 
	    
	    data.personalName = $.trim($("#personalName_askingPrice").val()); 
	    data.phone = $.trim($("#phone_askingPrice").val()); 
	    data.packageCode = $.trim($("#defaultPackageCode").val()); 
	    data.salesConsultantId = $.trim($("#salesConsultantId_askingPrice").val()); 
	    data.startDate = $.trim($("#startDate").val()); 
	    data.askingPriceContent = $.trim($("#askingPriceContent").val()); 
		var colorId = $("#defaultColorId").val();
		if(colorId!=undefined && colorId!=''){
			data.colorId = colorId;
		}

		$.ajax({
			type : 'POST',
			url : rootPath+'/wechat/api/askingPrice',
			contentType:"application/json",
			data: JSON.stringify(data),
			error:function(XMLHttpRequest, ajaxOptions, thrownError){
				
			},
			success : function(data){
				$('#askingPriceModal').modal({
					keyboard: false,
					backdrop:false
				});
			}
				
		});
		
		
	    	     
		 
	 });
	 
	//模态框确认
	$('#askingPriceModalSure').click(function(){
	    var packageCode = $("#defaultPackageCode").val();

		$('#askingPriceModal').modal('hide');
	    $("#personalName_askingPrice").val(''); 
	    $("#phone_askingPrice").val(''); 
	    $("#defaultPackageCode").val(''); 
	    $("#salesConsultantId_askingPrice").val(''); 
	    $("#startDate").val(''); 
	    $("#askingPriceContent").val(''); 
	    $('#askingPriceForm').data('bootstrapValidator').resetForm(true);
		window.location.href = rootPath +"/views/newCarShowroom/packageExhibition.html?packageCode="+packageCode;

	});	
	
	$('#selectLoveModelTopSure').click(function(){

		$('#selectLoveModelTop').modal('hide');

	});	
	 
     $("#askingPriceForm").addClass("active in");
     $("#carModelExhibitionDiv_askingPrice").removeClass("active in");
	 $("#carModelExhibitionDetailDiv_askingPrice").removeClass("active in");

     //选择品牌车系
     $(".selectBrandSeries").click(function(){
    	 
         var seriesCode = $("#defaultSeriesCode").val();
         
         //判断是否已经已有已选择的车系，车型，配置,如果存在直接进入车型配置选择页面，否则 进入品牌车系选择界面 
     	 if(seriesCode ==undefined || seriesCode==''){
     		 initBrandSeries();
         }else{
        	 initModelPackage(seriesCode);
         }
         
     });
     
     
     //从新选择品牌车系
     $(".againSelectBrandSeries").click(function(){
 		 initBrandSeries();
     });
 });


function dySelectColor(obj){ 
	var type = $(obj).attr("type");
	var packageCode = $(obj).attr("packageCode");

	var currentIndex = $("#"+packageCode+"_currentIndex").val();
	var len = $(obj).attr("len");
	if(type=="pre"){
		currentIndex = parseInt(currentIndex);
        if(currentIndex==0){
			currentIndex = len-1;
        }else{
        	currentIndex = currentIndex-1;
        }
	}else if(type=="next"){
		currentIndex = parseInt(currentIndex);
		if(currentIndex==len-1){
			currentIndex = 0;
		}else{
			currentIndex = currentIndex+1;
		}
		
		
	}
	$("#"+packageCode+"_currentIndex").val(currentIndex);
	for(var i=0;i<len;i++){
		if(currentIndex==i){
			$("#"+packageCode+"_"+i+"_name").show();
			$("#"+packageCode+"_"+i+"_color").show();
//			$("#"+packageCode+currentIndex"_name").show();
//			$("#"+packageCode+currentIndex"_color").show();
		}else{
			$("#"+packageCode+"_"+i+"_name").hide();
			$("#"+packageCode+"_"+i+"_color").hide();
		}
	}
	
	$("#defaultColorId").val($("#"+packageCode+"_"+currentIndex+"_colorId").val());
	
}

//初始化加载品牌车系界面 
function initBrandSeries(){
	
	var brandCode = $("#defaultBrandCode").val();
	if(brandCode ==undefined || brandCode==''){
		brandCode='';
	}
	$("#carModelExhibitionDiv_askingPrice").empty();
	
	$.ajax({
		method : 'get',
		url : rootPath+'/wechat/api/showroom/brands?brandCode='+brandCode,
		error:function(XMLHttpRequest, ajaxOptions, thrownError){
			alert("连接服务器错误!");
		},
		success : function(resultData){
			var wholeHtml = '';
			var brandHtml = '';
			var seriesHtml = '';
			
			$.each(resultData,function(brandIndex,brandObj){
				brandHtml = '<h4>'+brandObj.brandName+'</h4>';
				brandHtml +='<ul class="list-group">';
				$.each(brandObj.series,function(seriesIndex,seriesObj){		
					seriesHtml = '<a onclick="selectModelPackage(this)" seriesCode="'+seriesObj.seriesCode+'" href="#" class="list-group-item">'+
								  '<span class="glyphicon glyphicon-chevron-right form-control-feedback"></span>'+
								  seriesObj.seriesName+
	                              '</a>';
					brandHtml +=seriesHtml;
				});
				
				brandHtml +='</ul>';
				
				wholeHtml +=brandHtml;
			});
			
	    	 $("#carModelExhibitionDiv_askingPrice").append(wholeHtml);
		     $("#askingPriceForm").removeClass("active in");
		     $("#carModelExhibitionDetailDiv_askingPrice").removeClass("active in");
		     $("#carModelExhibitionDiv_askingPrice").addClass("active in");
		     
		}
		
		
	});

}


//初始化加载车型配置页面
function initModelPackage(seriesCode){
	
	$("#carModelPackageExhibitionDiv_askingPrice").empty();
	$.ajax({
		method : 'get',
		url : rootPath+'/wechat/api/showroom/series?seriesCode='+seriesCode,
		error:function(XMLHttpRequest, ajaxOptions, thrownError){
			alert("连接服务器错误!");
		},
		success : function(resultData){
			var wholeHtml = '';
			if(resultData!=undefined && resultData!=''){
				$("#modelNameSpan").html(resultData.seriesName);
				
				$("#defaultBrandName").val(resultData.brandName)
				$("#defaultSeriesName").val(resultData.seriesName)
			}
			$.each(resultData.models,function(modelIndex,modelObj){
				
				var modelHtml =  '<ul class="list-group">'
							+'    <a href="#" class="list-group-item active">'
							+         modelObj.modelName
					        +'    </a>';
				
				$.each(modelObj.packages,function(packageIndex,packageObj){
					var packageHtml = '<a href="#" onclick="selectConcretePackage(this)" guidePrice='+packageObj.guidePrice+' localPrice='+packageObj.localPrice+' modelCode='+modelObj.modelCode+' packageCode='+packageObj.packageCode+' packageName='+packageObj.packageName+' class="list-group-item">'
							  	 +'  <span class="glyphicon glyphicon glyphicon-heart form-control-feedback"></span>'
							  	 +       packageObj.packageName
					             +'</a>';
					
					 
					modelHtml +=packageHtml;
					
				});
				
				modelHtml +='</ul>';
				
				wholeHtml +=modelHtml;
				
			});
			
			 $("#carModelPackageExhibitionDiv_askingPrice").append(wholeHtml);
		     $("#askingPriceForm").removeClass("active in");
		     $("#carModelExhibitionDiv_askingPrice").removeClass("active in");
			 $("#carModelExhibitionDetailDiv_askingPrice").addClass("active in");
			
		}
	});

}
 
 
 
 //选择车型配置页面
 function selectModelPackage(obj){
	 var seriesCode = $(obj).attr("seriesCode");
	 
	 $("#defaultSeriesCode").val(seriesCode);
	 initModelPackage(seriesCode);
 }
 
 
function dySelectColorEx(obj){ 
	var type = $(obj).attr("type");
	var packageCode = $(obj).attr("packageCode");

	var currentIndex = $("#"+packageCode+"_currentIndex_ex").val();
	var len = $(obj).attr("len");
	if(type=="pre"){
		currentIndex = parseInt(currentIndex);
        if(currentIndex==0){
			currentIndex = len-1;
        }else{
        	currentIndex = currentIndex-1;
        }
	}else if(type=="next"){
		currentIndex = parseInt(currentIndex);
		if(currentIndex==len-1){
			currentIndex = 0;
		}else{
			currentIndex = currentIndex+1;
		}
		
		
	}
	$("#"+packageCode+"_currentIndex_ex").val(currentIndex);
	for(var i=0;i<len;i++){
		if(currentIndex==i){
			$("#"+packageCode+"_"+i+"_name_ex").show();
			$("#"+packageCode+"_"+i+"_color_ex").show();
//				$("#"+packageCode+currentIndex"_name").show();
//				$("#"+packageCode+currentIndex"_color").show();
		}else{
			$("#"+packageCode+"_"+i+"_name_ex").hide();
			$("#"+packageCode+"_"+i+"_color_ex").hide();
		}
	}
	
	$("#defaultColorId").val($("#"+packageCode+"_"+currentIndex+"_colorId_ex").val());
		
}


//加载配置颜色
function loadPackageColors(packageCode){
	
 	$.ajax({
 		method : 'get',
 		url : rootPath+'/wechat/api/showroom/colors?packageCode='+packageCode,
 		error:function(XMLHttpRequest, ajaxOptions, thrownError){
 		},
 		success : function(resultData){
 			$(".attachSelectModelPackageDiv").empty();
			if(resultData!=undefined && resultData!='' && resultData.length >0){
				
				var colorsHtml = '';
				colorsHtml += '             <table>';
				colorsHtml += '                <tr>';
				colorsHtml += '                  <td><a type="pre" len='+resultData.length+' packageCode='+packageCode+'  onclick="dySelectColorEx(this)" href="#">＜&nbsp;&nbsp;</a></td>';
				colorsHtml += '                        <input id="'+packageCode+'_currentIndex_ex" type="hidden" value="0">';
    			$.each(resultData,function(packageColorIndex,packageColorObj){
    				colorsHtml += '                        <input id="'+packageCode+'_'+packageColorIndex+'_colorId_ex" type="hidden" value="'+packageColorObj.colorId+'">';
    				if(packageColorIndex==0){
    				   $("#defaultColorId").val(packageColorObj.colorId);

    					colorsHtml += '                  <td class="colorParam" id="'+packageCode+'_'+packageColorIndex+'_name_ex"><h6>'+packageColorObj.colorName+'&nbsp;</h6></td>';
        				colorsHtml += '                  <td id="'+packageCode+'_'+packageColorIndex+'_color_ex"><div  style="background-color: #'+packageColorObj.colorValue+';width: 20px;height: 10px"></div></td>';
    				}else{
    					colorsHtml += '                  <td class="colorParam" id="'+packageCode+'_'+packageColorIndex+'_name_ex" style="display: none"><h6>'+packageColorObj.colorName+'&nbsp;</h6></td>';
    					colorsHtml += '                  <td id="'+packageCode+'_'+packageColorIndex+'_color_ex" style="display: none"><div  style="background-color: #'+packageColorObj.colorValue+';width: 20px;height: 10px"></div></td>';
    				}
    			});
				
    			colorsHtml += '                  <td><a type="next" len='+resultData.length+' packageCode='+packageCode+'  onclick="dySelectColorEx(this)" href="#">&nbsp;&nbsp;＞</a></td>';
    			colorsHtml += '                </tr>';
    			colorsHtml += '             </table>';
    			$(".attachSelectModelPackageDiv").append(colorsHtml);
			}
 		}
 	});
}
 
 //选择具体的车型配置
 function selectConcretePackage(obj){
	 var modelCode = $(obj).attr("modelCode");
	 var packageCode = $(obj).attr("packageCode");
//	 var packageName = $(obj).attr("packageName");
	 var guidePriceTemp = $(obj).attr("guidePrice");
	 var localPriceTemp = $(obj).attr("localPrice");
	 
	if(guidePriceTemp!=undefined && guidePriceTemp!=''){
		$(".guidePriceAp").html(guidePriceTemp+"万");
	}
	if(localPriceTemp!=undefined && localPriceTemp!=''){
		$(".localPriceAp").html(localPriceTemp+"万");
	}
	
	loadPackageColors(packageCode);
	
	 var packageName = $(obj).text();
	 
	 $(".packageNameSpan").html(packageName);
	 
	 $("#defaultModelCode").val(modelCode);
	 $("#defaultPackageCode").val(packageCode);
	 $("#defaultPackageCode_ex").val(packageCode); 	 
	 var brandName =$("#defaultBrandName").val();
	 var seriesName =$("#defaultSeriesName").val();
	 $("#seriesImageAp").attr("src",rootPath+'/images/'+brandName+'/外观/'+seriesName+'/'+seriesName+'.jpg');
	 $("#seriesImageApNoLoveModel").attr("src",rootPath+'/images/'+brandName+'/外观/'+seriesName+'/'+seriesName+'.jpg');
	 
     $("#carModelExhibitionDiv_askingPrice").removeClass("active in");
	 $("#carModelExhibitionDetailDiv_askingPrice").removeClass("active in");
     $("#askingPriceForm").addClass("active in");
 }

 
 
